<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,aximum-scale=1.0">
    <style>
        *{margin: 0;padding: 0}
        body{
            background: url("img/bg.jpg");
        }
       header{
           width: 10rem;
           height: 2rem;
           text-align: center;
           color:white;
       }
        header h1{
            font-size: 0.5rem;
            line-height: 1.3rem;
        }
        header p{
            font-size: 0.3rem;;
        }

        .singer{
            width: 8rem;
            height: 8rem;
            border-radius: 50%;
            border: 1px solid white;
            margin: auto;
        }
        .singer div{
            width: 7.6rem;
            height: 7.6rem;
            background: rgba(255,255,255,0.5);
            margin: 0.2rem;
            border-radius: 50%;
        }
        .singer img{
            width: 7rem;
            height: 7rem;
            border-radius: 50%;
            margin: 0.3rem;
        }

        .progress{
            width: 9rem;
            height: 0.1rem;
            background: #c03;
            margin: 1rem auto;
        }
        .bg{
            width: 0px;
            height: 0.1rem;
            background: greenyellow;
        }
        .bar{
            width: 0.2rem;
            height: 0.2rem;
            background: white;
            border-radius: 50%;
            transform: translate(0rem,-0.15rem);/*硬件加速，提升性能*/
        }
        .btns{
            width: 8rem;
            margin: auto;
        }
        .btns div{
            float: left;
            margin: 0.5rem;
            font-size: 1.5rem;
        }

        .pause{display: none}

        .rotate{
            animation: rot 10s linear infinite;/*名称，时间，匀速，无限*/
        }
        @keyframes rot {
            to{
                transform: rotate(360deg);
            }
        }
    </style>
    <link rel="stylesheet" href="font/iconfont.css">
</head>
<body>
    <header>
        <h1>爱不可及</h1>
        <p>王菲</p>
    </header>
    <section class="singer">
        <div class="rotate">
            <img src="img/tx.jpg" alt="">
        </div>
    </section>
<section class="progress">
    <div class="bg"></div>
    <div class="bar"></div>
</section>
<section class="btns">
    <div class="prev iconfont">&#xe6de;</div>
    <div class="play iconfont">&#xe60d;</div>
    <div class="pause iconfont">&#xe62f;</div>
    <div class="next iconfont">&#xe6dd;</div>
</section>
    <audio src="mp4/王菲+-+爱不可及.mp3" id="myMusic"> </audio>
</body>
<script>
    document.getElementsByTagName("html")[0].style.fontSize=
            document.documentElement.clientWidth/10+'px';
</script>
<script>
    var myMusic=document.getElementById("myMusic");
    var oplay=document.getElementsByClassName("play")[0];
    var pause=document.getElementsByClassName("pause")[0];
    var progress=document.getElementsByClassName("progress")[0];
    var bar=document.getElementsByClassName("bar")[0];
    var bg=document.getElementsByClassName("bg")[0];
    /*var onOFF=true;
    oplay.onclick=function(){ //一个按钮这样写
        if(onOFF){
            myMusic.play();
        }else {
            myMusic.pause();
        }
        onOFF=!onOFF;
    }*/
    //播发
    oplay.onclick=function(){
        myMusic.play();
        pause.style.display="block";
        this.style.display="none"
    };
    //暂停
    pause.onclick=function(){
        myMusic.pause();
        oplay.style.display="block";
        this.style.display="none"
    };
    //计算笑话快
    //监听进度 timeupdate时间更新事件 currentTime当前时间 duration总时间
    var w=progress.offsetWidth - bar.offsetWidth;
    myMusic.addEventListener("timeupdate",function(){
        //console.log(this.currentTime);
        //console.log(this.duration)
        var s=this.currentTime/this.duration;
        bar.style.transform= "translate("+s*w+"px,-0.15rem)";
        bg.style.width=s*w+'px'
    });

    //触屏事件笑话快托拽进度条
    var x= 0,l= 0, _left=0;
    bar.addEventListener("touchstart",function(e){
         x= e.changedTouches[0].pageX;//手指左边
        //获取原始坐标
         //l= bar.offsetLeft;
        document.addEventListener("touchmove",move);
        //触屏结束解绑
        document.addEventListener("touchend",function(){
            document.removeEventListener("touchmove",move);
            l=_left;
        })
    });

    function move(e){
        var x1= e.changedTouches[0].pageX;
         _left=x1-x+l;
        if(_left<0){
            _left=0
        }else if(_left>w){
            _left=w;
        }
        bar.style.transform= "translate("+_left+"px,-0.15rem)";
        bg.style.width=_left+'px';
        myMusic.currenTime=_left/w*myMusic.duration;
    }
</script>
</html>